#include <stdio.h>
#include "pe12-2a.h"

#define kalon 7.61421
#define USkalon 34.17322
 
static double kilometers;
static double oils; //定义了剩余的油量
extern int mode;

void get_info()
{
    int is_quit = 1; //退出标记
    int scanned;    //扫描记录

    printf("Enter distance travelled in kilometres:\n");
    while (is_quit)
    {
        scanned = scanf("%lf", &kilometers);
        if (scanned != 1 && kilometers > 0)
        {
            printf("Pls re enter a kilometers:\n");
            while (getchar() != '\n') //清空字符缓冲区
            {
                continue;
            }
            scanned = scanf("%lf", &kilometers);
        }
        else
        {   
            if(mode == 0){  //choose 英值单位
                oils =   kilometers /  kalon;             

            }
            if (mode == 1)
            {
                oils = kilometers / USkalon;
            }
            if (mode >= 2){
				printf("Invalid mode selected ,mode 1(US) selected!\n");
				oils = kilometers / USkalon;
			}
            
            is_quit = 0;
        }
    }
}

void show_info()
{
    printf("you have selected mode %d\n",mode);
    printf("Enter fuel  consumed in liters: %lf\n",oils);
}

void set_mode(int in_mode)
{
    if (in_mode == 0 && in_mode == 1)
        mode = in_mode;
}